package com.gyt.manage.function.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.gyt.data.dao.risk.FunctionMapper;
import com.gyt.framework.component.AbtComponent;
import com.gyt.framework.domain.function.risk.FunctionLibraryInfo;
import com.gyt.framework.response.Page;
import com.gyt.framework.response.result.AbtExperimentInfoResult;
import com.gyt.manage.function.ManageFunctionApplication;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.runner.RunWith;
//import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.List;


/**
 * 1、使用@MybatisTest，如果不加注解@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)，
 * 那么mybatis使用的是内存数据库，并不是真实的tddl的数据库，会报表不存在的错
 * 2、@Rollback(false) 单测完成默认会将数据回滚，如果不想回滚，想保留在数据库中，要加(false)
 * @author v_yantgao
 */
@RunWith(SpringJUnit4ClassRunner.class)
@Rollback(false)
@ActiveProfiles("test")
//@MapperScan(basePackages = {"com.gyt"})
@SpringBootTest(classes = ManageFunctionApplication.class)
public class MyTestController {

    private static final Logger logger= LoggerFactory.getLogger(MyTestController.class);

    @Autowired
    private FunctionMapper functionMapper;

    @Autowired
    private AbtComponent abtComponent;

    @Test
    public void testUpdateFuns(){
        FunctionLibraryInfo libraryInfo = functionMapper.getFunctionLibraryInfoById(2);
        logger.info("libraryInfo:{}",JSON.toJSONString(libraryInfo));
    }
    @Test
    public void testFuns(){
        FunctionLibraryInfo libraryInfo = functionMapper.getFunctionLibraryInfoById(2);
        logger.info("libraryInfo:{}",JSON.toJSONString(libraryInfo));
    }

    @Test
    public void testAbt(){
        Page<AbtExperimentInfoResult> expInfoResultPage = abtComponent.getAbtExperimentList(null, "test_layer_alg_1", "1", 2, 2);
        logger.info("expInfoResultPage:{}",JSON.toJSONString(expInfoResultPage));
    }

    @Test
    public void testAll() {
        String timeStr = "2021-01-14 00:00:00";
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            long time = format.parse(timeStr).getTime();
            System.out.println(format.format(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
